<?php
namespace Api\Controller;
use Think\Controller;
class OrderController extends CommonController {
    public function index(){
        $map = array();
        $map['wid'] = session('wid');
        $map['is_pay'] = 1;
        if($_GET['openid']){
            $map['openid'] = $_GET['openid'];
        }
        if($_GET['shop_id']){
            $map['shop_id'] = $_GET['shop_id'];
        }
        if($_GET['type']){
            $map['type'] = $_GET['type'];
        }
        $list = M("Order")->where($map)->order("create_time desc")->select();
        //是否评价过
        foreach ($list as $k => $v) {
            $row = M("shop_evaluate")->where(['order_id' => $v['id']])->find();
            $row ? $list[$k]['is_pinglun'] = 1 : $list[$k]['is_pinglun'] = 0;
        }

        $this->ajaxReturn($list);
    }

    public function item(){
        $map['a.out_trade_no'] = I('id');
        $map['a.wid'] = session('wid');
        $map['a.is_pay'] = array('gt', 0);
        $type = M("Order")->where(['out_trade_no' => I('id'), 'wid' => session('wid'), 'is_pay' => ['gt', 0]])->getField('type');
        if ($type == 'hotel') {
            $info = M("Order")->where(['out_trade_no' => I('id'), 'wid' => session('wid'), 'is_pay' => ['gt', 0]])->find();
            //总金额
            $info['price'] = $info['pay_money'];
            //
            $info['coupon_price_goods'] = $info['pay_money'];
        } else {
            $info = M("Order")->alias('a')->field('a.*, b.price as coupon_price_goods')->join('tp_goods b on a.goods_id = b.id')->where($map)->find();
        }
        $this->ajaxReturn($info);
    }
}